home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#3.ZIP / ARTICLE.3_2 < prev    next >
Encoding:
Text File  |  1995-01-25  |  5.9 KB  |  168 lines

  1.  
  2.  
  3. ;       TBSCAN's flags     by qark
  4. ;       +------------+
  5. ;
  6. ;    I realise that this sort of thing was done in a crypt journal one time
  7. ;    but since then Franz has added four or five new flags and they haven't
  8. ;    been covered.  While working on my polymorphics for Hemlock I discovered
  9. ;    how the '@' flag was triggered and had to share my knowledge with the
  10. ;    world.
  11. ;
  12.  
  13. codeseg segment
  14. main    proc    far
  15.     assume cs:codeseg,ds:codeseg
  16.  
  17.     mov     ax,codeseg
  18.     mov     ds,ax
  19.  
  20.     mov     ah,9                    ;Display a message.
  21.     mov     dx,offset tbscan
  22.     int     21h
  23.  
  24. ;----------------------------------------------------------------------------
  25. ;    The TBSCAN '@' flag.
  26. ;
  27. ;    TBSCAN says "Encountered instructions which are not likely to be
  28. ;    generated by an assembler, but by some code generator like a
  29. ;    polymorphic virus."
  30. ;
  31. ;    To give you an example of how TBSCAN finds this you must understand
  32. ;    that in many circumstances it is possible to have two different ways
  33. ;    of representing the one instruction.
  34. ;
  35. ;    We will take 'OR CX,CX' as an example.  It can be represented by:
  36. ;       db 09h,0c9h  or  db 0bh,0c9h
  37. ;    The first two-byte combination sets off the flag, the second does not.
  38. ;    TBSCAN is correct in flagging it, because the first 'or cx,cx' is never
  39. ;    produced naturally.
  40. ;
  41. ;     |0   0   0   0   1   0 | 1 | 1  |   <- 0B
  42. ;     |0   0   0   0   1   0 | 0 | 1  |   <- 09 (triggers a tbscan flag)
  43. ;     |                      |   |    |
  44. ;     |      opcode          |dir|word|
  45. ;     |                      |bit|    |
  46. ;
  47. ;    Above is the format of the first byte of the OR instruction.  As you
  48. ;    can see the 'direction bit' is the difference between them.  If the
  49. ;    direction bit isn't set (which is what TBSCAN is looking for) it
  50. ;    means that the source and destination fields exchange roles.  A compiler
  51. ;    won't do this, but a polymophic engine will.
  52. ;
  53. ;    Likewise there are two ways of doing MOV AX,1234h
  54. ;       db 05h,34h,12h  or  db 81h,0c0h,34h,12h
  55. ;    The second one will trigger the '@' flag as well.  This is because
  56. ;    with AL/AX the instuctions are one byte less in size than with the
  57. ;    other registers.  An assembler will NEVER use the method that takes
  58. ;    more bytes, but a polymorphic engine will.  These are all things to
  59. ;    watch out for when constructing a polymorphic engine.  Remember to
  60. ;    make the instructions natural.
  61. ;       
  62. ;    Franz deserves a clap for spotting these little things.  Most of the
  63. ;    other AV companies are content to sit on what they've got, but TBAV
  64. ;    is continually improves.  It is a good product.
  65. ;
  66. ;----------------------------------------------------------------------------
  67.  
  68.  
  69.     db      0bh,0c9h                ;OR CX,CX
  70.     db      9,0c9h                  ;OR CX,CX
  71.  
  72.     db      05h,34h,12h             ;ADD AX,1234h
  73.     db      81h,0c0h,34h,12h        ;ADD AX,1234h
  74.  
  75.  
  76.  
  77. ;----------------------------------------------------------------------------
  78. ;    The TBSCAN '1' flag.
  79. ;
  80. ;    TBSCAN says "Found instructions which require a 80186 processor or 
  81. ;    above."
  82. ;
  83. ;    This is pretty obvious.  Just anything that won't run on an 8088.
  84. ;    Easy enough to avoid.
  85. ;
  86. ;----------------------------------------------------------------------------
  87.  
  88.     shr     ax,3                    ;This instruction only works on 286+
  89.  
  90. ;----------------------------------------------------------------------------
  91. ;    The TBSCAN 'A' flag.
  92. ;
  93. ;    TBSCAN says "Suspicious Memory Allocation.  Program uses an unusual
  94. ;    way to search for, and/or allocate memory."
  95. ;
  96. ;    It just looks for a compare with 'Z' instruction.
  97. ;
  98. ;----------------------------------------------------------------------------
  99.     
  100.     cmp     byte ptr [0],'Z'                ;Often used while playing
  101.                         ;with MCB's.
  102.  
  103.  
  104. ;----------------------------------------------------------------------------
  105. ;    The TBSCAN 'U' flag.
  106. ;
  107. ;    TBSCAN says "Undocumented interrupt/DOS call.  The program might be just
  108. ;    tricky but can also be a virus using a non-standard way to detect   
  109. ;    itself."
  110. ;    
  111. ;    The only thing you have to watch out for here is calling int21 above
  112. ;    AH=6e or use interrupts that are obscure (above 80h probably).
  113. ;    There are plenty of unused int21 functions below 6e so it shouldn't be
  114. ;    hard.
  115. ;
  116. ;----------------------------------------------------------------------------
  117.  
  118.     mov     ax,6e00h                ;This one is ok.
  119.     int     21h
  120.  
  121.     mov     ax,6f00h                ;This one causes a flag.
  122.     int     21h
  123.  
  124.     mov     ax,09191h               ;This one is ok.
  125.     int     13h
  126.  
  127.     mov     ax,09191h               ;This one causes a flag.
  128.     int     0b6h
  129.  
  130.  
  131.     mov     ax,4c00h
  132.     int     21h             ;Terminate
  133.  
  134. tbscan          db      'TBSCAN FLAGS ME$'
  135.  
  136. ;----------------------------------------------------------------------------
  137. ;    The TBSCAN 'S' flag.
  138. ;
  139. ;    TBSCAN says "Contains a routine to search for executable (.COM and .EXE)
  140. ;    files."
  141. ;
  142. ;    This just means that '*.com' or '*.exe' is in the code somewhere.  You
  143. ;    shouldn't have to worry about this because wild cards are only used
  144. ;    in direct action viruses.  
  145. ;
  146. ;----------------------------------------------------------------------------
  147.  
  148. wildcard        db      '*.com',0
  149.     
  150. main    endp
  151. codeseg ends
  152.  
  153.  
  154. ;----------------------------------------------------------------------------
  155. ;    The TBSCAN 'K' flag.
  156. ;
  157. ;    TBSCAN says "Unusual stack.  The program has a suspicious or an odd
  158. ;    stack."
  159. ;
  160. ;    That flag can't be demonstrated here, but what it means is that the
  161. ;    SS:SP points past the end of the file.  This is only for EXE files
  162. ;    and can be seen in some of my viruses.  There isn't much that can
  163. ;    be done about this unless you change the stub/infection code to your
  164. ;    virus.
  165. ;
  166. ;----------------------------------------------------------------------------
  167.  
  168.